package cn.com.qtgl.userfilters.model.entity;

import cn.com.qtgl.userfilters.model.enums.UserFilterType;
import cn.com.qtgl.userfilters.model.pojo.UserFilters;
import cn.melonlib.cores.commons.model.entity.AbstractCustomIdEntity;
import cn.melonlib.cores.commons.model.entity.IRecordEntity;
import cn.melonlib.cores.commons.model.entity.TenantEntity;
import cn.melonlib.cores.model.anno.ModelComment;
import lombok.Data;
import lombok.EqualsAndHashCode;
import org.hibernate.annotations.GenericGenerator;

import javax.persistence.*;

@Data
@EqualsAndHashCode(callSuper = true)
@ModelComment("UserFilter对象")
@Entity(name = "DbUserFilter")
@Table(name = "sec_db_user_filter")
public class DbUserFilter extends AbstractCustomIdEntity<String> implements IRecordEntity, TenantEntity {

    @Id
    @GeneratedValue(generator = "snowflake")
    @GenericGenerator(name = "snowflake",strategy = "cn.melonlib.cores.commons.model.entity.CustomIdGenerator")
    private String id;

    @ModelComment("人员选择器类型")
    @Enumerated(EnumType.STRING)
    public UserFilterType userFilterType=UserFilterType.USER;

    @ModelComment("创建人ID")
    private String creatorId;

    @ModelComment("创建人账号")
    private String creatorCode;

    @ModelComment("创建人姓名")
    private String creatorName;
    /**
     * 创建时间
     */
    @ModelComment("创建时间")
    private Long createDateTime = System.currentTimeMillis();

    /**
     * 最后修改时间
     */
    @ModelComment("最后修改时间")
    private Long lastModifiedDateTime = System.currentTimeMillis();


    /**
     * 排序，默认安装当前时间戳
     */
    @ModelComment("默认排序字段")
    private Long sortNum=System.currentTimeMillis();


    @ModelComment("是否删除")
    private Boolean removed;

    @ModelComment("租户ID")
    private String tenantId;
    @Column(length = 2000)

    @ModelComment("租户编号")
    private String tenantCode;

    @ModelComment("租户名称")
    private String tenantName;

    @ModelComment("人员选择器字符串")
    private String userFilter;

    @Override
    public String generatorId() {
        String id=userFilter;
        if(UserFilters.validUserFilters(id)){
            return id;
        }else{
            throw new RuntimeException("userfilter验证失败");
        }

    }


}
